import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {ChildComponent} from "../child/child.component";
import {FormsModule} from "@angular/forms";
import { MyDerirective01Directive } from '../../directives/my-derirective01.directive';

@Component({
  selector: 'app-parent',
  standalone: true,
  imports: [ChildComponent, FormsModule, MyDerirective01Directive],
  templateUrl: './parent.component.html',
  styleUrl: './parent.component.css'
})
export class ParentComponent {
  childrenName: string = "父组件传递属性给子组件";
  cnt: number = 100;
  username: string = "默认值1";

  @ViewChild("divElement",{static: true}) divElement :ElementRef = new ElementRef<any>(undefined);

  @ViewChild("ch1",{static: true}) ch1 :any;

  handlerCry($event: string) {
    this.username = this.username + " ====" + $event;
    console.log(this.username);
  }

  handlerHappy($event: string) {

    console.log("来自子组件的值",$event);
    this.username = this.username + $event;
    console.log(this.username);
  }

  print() {
    console.log(this.divElement)
    this.divElement.nativeElement.html = "printing"
    this.divElement.nativeElement.style.color = "red"
    this.divElement.nativeElement.style.background = "yellow"
    console.log(this.ch1)
  }
}
